// pages/home/home.js
let {getHomeData} = require("../../api/home")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 轮播图数据
    imgs:[
      "/images/banner01.jpg",
      "/images/banner02.jpg",
      "/images/banner03.jpg",
      "/images/banner04.jpg"
    ],
    // 分类数据
    category:[
      {
        image:"/images/icon-qiandao.png",
        text:"签到"
      },
      {
        image:"/images/icon-fujin.png",
        text:"附近"
      },
      {
        image:"/images/icon-zhanhui.png",
        text:"展会"
      },
      {
        image:"/images/icon-fuli.png",
        text:"福利"
      },
      {
        image:"/images/icon-muma.png",
        text:"木马"
      },
      {
        image:"/images/icon-qinzi.png",
        text:"亲子"
      },
      {
        image:"/images/icon-tiyu.png",
        text:"体育"
      },
      {
        image:"/images/icon-xingxing.png",
        text:"星星"
      },

    ],

    // 商品数据
    goodsList:[
      {
        id:1,
        goodsImage:"/images/goods01.jpg",
        goodsName:"商品一",
        goodsPrice:"200",
      },
      {
        id:2,
        goodsImage:"/images/goods03.jpg",
        goodsName:"商品二",
        goodsPrice:"1560",
      },
      {
        id:3,
        goodsImage:"/images/goods02.jpg",
        goodsName:"商品三",
        goodsPrice:"110",
      },
    ],
    hot:null,//热门爆款
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    getHomeData().then(res=>{
      let sections = res.data.data.sections;
      var hot_lists =[];
      sections.forEach((item) => {
        if(item.view_type == "list_two_type13"){
          hot_lists = hot_lists.concat(item.body.items)
        }
      })
      this.setData({
        imgs:sections[0].body.items,
        category:sections[1].body.items.concat(sections[2].body.items),
        hot:sections[6].body.items[0],
        goodsList:hot_lists
      })
    })
  },

    // 获取图片信息
    bindloadFun(event) {
      let { height, width } = event.detail;
      // 获取硬件系统信息
      wx.getSystemInfo({
          success: (result) => {
              this.setData({
                  swiperHeight: result.windowWidth / width * height
              })
          },
      })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    // console.log(123);
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})